﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dimebrain.TweetSharp.Extensions;
using Dimebrain.TweetSharp.Fluent;
using Dimebrain.TweetSharp.Model;
using System.Collections;

namespace TwitterTestApp
{
    [Serializable]
    class MessageListContainer : List<DirectMessage>
    {
        private List<DirectMessage> messageList = new List<DirectMessage>();
        public List<DirectMessage> MessageList
        {
            get { return this.ToList(); }
            internal set { messageList = value; }
        }

        public MessageListContainer() { }

        public MessageListContainer(IEnumerable<DirectMessage> messages)
        {
            MessageList = messages as List<DirectMessage>;
        }

        public IEnumerable<DirectMessage> getMessages(DirectMessage.Types types)
        {
            List<DirectMessage> results = new List<DirectMessage>();
            foreach (var m in MessageList)
            {
               if ((m.MessageTypes & types) == types)
                    results.Add(m);
            }
            return results.AsEnumerable(); 
        }

        public bool contains(DirectMessage m)
        {
            bool c = false;
            foreach (var message in MessageList)
            {
                if (m.TDM.Id == message.TDM.Id)
                {
                    c = true;
                    break;
                }
            }
            return c;
        }

        new public int Count(DirectMessage.Types types)
        {
            int count = 0;
            foreach (var m in MessageList)
            {
                if ((m.MessageTypes & types) == types)
                    count++;
            }
            return count;
        }

        public TwitterDirectMessage getMostRecent()
        {
            DateTime recent = DateTime.MinValue;
            TwitterDirectMessage tdm = null;
            foreach (var m in MessageList)
            {
                if (m.TDM.CreatedDate > recent)
                {
                    recent = m.TDM.CreatedDate;
                    tdm = m.TDM;
                }
            }
            return tdm;
        }
    }
}


